#!/usr/bin/perl -w
package conf;
use strict;
use Net::SMTP_auth;
no warnings('once');  
    #这一句，可以避免出现由于变量只使用一次出现的 use only once 警告
require '../conf/config.pl';

$ENV{TZ} = 'Asia/Shanghai'; # 设置时区

our %db_conf = %conf::db_conf ;  
our %em_conf = %conf::em_conf ;

sub sendMail {
	my ($to,$subject,$message) = @_;

	#smtp邮件服务器和端口
	my $smtpHost = $em_conf{'smtpHost'};
	my $smtpPort = $em_conf{'smtpPort'};
	my $sslPort = $em_conf{'sslPort'};
	
	#smtp服务器认证用户名密码(就是你登陆邮箱的时候的用户名和密码)
	my $username = $em_conf{'username'};
	my $passowrd = $em_conf{'password'};	
	my $from = $em_conf{'from'};	
	
	my @helo = split /\@/,$from;	
	#普通方式，通信过程不加密
	my $smtp = Net::SMTP_auth->new(
	                "$smtpHost:$smtpPort",
	                Hello   => $helo[1],
	                Timeout => 30
	                ) or die("Error:连接到$smtpHost失败！");
	$smtp->auth('LOGIN',$username,$passowrd) or die("Error:认证失败！");

	#设置邮件header
	my $header = << "MAILHEADER";
Mime-Version:1.0
Content-Type:text/html;charset="UTF-8"
Content-Trensfer-Encoding:7bit 
Subject: $subject
From:$from
MAILHEADER
	
	#发送邮件
	$smtp->mail($from);
	#$smtp->to($to);
	# Multi Recipients
	my @recipients= split /,/,$to;
	my $n = 0;
	while ($recipients[$n]) {
	 $smtp->to($recipients[$n]);
	 $n++;
	}
	$smtp->data();
	$smtp->datasend($header);
	$smtp->datasend("To:$to\n");
	$smtp->datasend("\n");
	$smtp->datasend($message);
	$smtp->dataend();
	$smtp->quit();
}



#sendMail("smtp.hwccl.com","25","it","S20d43",'it@hwccl.com',"测试邮件",'meansonw@gmail.com',"策划is");

1;